package com.tanhua.server.controller;

import com.tanhua.model.dto.AnswerDTO;
import com.tanhua.model.vo.ExamVO;
import com.tanhua.model.vo.ReportVO;
import com.tanhua.server.service.MeasuringSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 测灵魂控制层
 */
@RestController
@RequestMapping("testSoul")
public class MeasuringSoulController {

    @Autowired
    private MeasuringSoulService measuringSoulService;

    /**
     * 展示试卷列表
     * @return
     */
    @GetMapping
    public ResponseEntity testSoulExamList(){

        List<ExamVO> examList = measuringSoulService.findExamListWithUser();
        return ResponseEntity.ok(examList);
    }

    /**
     * 灵魂测试答题
     */
    @PostMapping
    public ResponseEntity commitSoulAnswers(@RequestBody Map<String,List<AnswerDTO>> answers){

        String reportId = measuringSoulService.commitAnswers(answers);
        return ResponseEntity.ok(reportId);
    }


    @GetMapping("report/{id}")
    public ResponseEntity showReport(@PathVariable("id")Integer id){
        ReportVO reportVO = measuringSoulService.selectReportByReportId(id);
        return ResponseEntity.ok(reportVO);
    }
}
